<template>
  <div>
    <el-col :span="24" class="bg1">
      <div class="grid-content bg-purple">
        <FormPanel ref="formPanel" :list="formList" :cols="1" :labelWidth="120" :isSubmitBtn="false" @formChange="formChangeHandle"/>
      </div>
    </el-col>

    <div class="dialogBottmView">
      <multiuse-button type="primary" :click="saveDialog.bind()">保 存</multiuse-button>
      <el-button size="small" type="primary" class="btnStyle" @click="closeMenu('3')">关闭
      </el-button>

    </div>

  </div>
</template>

<script>
import {getByThreeId, updateMaintain} from '@/api/repair/threePacksOfManager/regulationsQueryCDuan';


  import {dictionary} from '@/utils/dictMixin';
  import {isEmpty} from '@/utils/utils';
  import {exportExcelFile} from '@/utils/index';

  export default {
    name: 'detail',
    mixins: [dictionary],
    /*handleType show   活动审核  show-1  索赔审核*/
    props: ['handleType', 'threeId'],
    data()
    {
      this.saveData = null;
      return {

        formList: this.createFormList(),
        detailObj: {},
      };
    },
    components: {},
    mounted()
    {
      this.getData();


    },
    methods: {
      formChangeHandle(val) {
        this.saveData = val;
      },
      //保存
      async saveDialog() {
        let err = this.$refs.formPanel.submitForm();
        if (err) {
          this.$notify.error({ title: '提示信息', message: '请检查提交数据' });
          return;
        }
        let params = Object.assign({}, this.saveData);
        let res = await updateMaintain(params);
        console.log(res);
        if (res.resultCode === 200) {
          this.$emit('save');
          return this.$notify.success({ title: '提示信息', message: '保存成功' });
        } else {
          this.loading = false;
          this.$notify.error({ title: '提示信息', message: res.errMsg || '保存失败!' });
        }
        this.loading = false;
      },
      /*根据ID查询*/
      async getData()
      {
        let res = await getByThreeId({'id': this.threeId});

        if (res.resultCode == 200 && res.success == true)
        {
          let data = isEmpty(res['data']) ? {} : res['data'];

          for (let i in data)
          {
            this.formList.map(x =>
            {
              if (i == x.fieldName)
              {
                x.initialValue = data[i];
              }
            });
          }
        }

      },
      async closeMenu(type)
      {
        this.$emit('close')
      },

      createFormList()
      {

        return [
          {
            type: 'INPUT',
            label: '规则编号',
            fieldName: 'threeNo',
            style: {width: '200px'},
            itemList: [],
            disabled: true,
            placeholder: '',
            // rules: [{required: true, trigger: 'change'}],
            initialValue: ''
          },
          {
            type: 'INPUT',
            label: '规则名称',
            fieldName: 'name',
            style: {width: '200px'},
            rules: [{required: true,  message: '规则名称不能为空',trigger: 'change'}],
            placeholder: '请输入',
            initialValue: ''
          },
          // {
          //   type: 'SELECT',
          //   label: '规则类型',
          //   fieldName: 'type',
          //   placeholder: '',
          //   disabled: true,
          //   rules: [{required: false, trigger: 'change'}],
          //   initialValue: '',
          //   itemList: this.createDictList(1023)
          //
          // },
          {
            type: 'INPUT_NUMBER',
            label: '法定时限（月）',
            fieldName: 'months',
            placeholder: '请输入',
            style: {width: '200px'},
            initialValue: '',
            rules: [{required: true, message: '法定时限不能为空', trigger: 'change'}, {pattern: /^\d+$/, message: '请输入正整数', trigger: 'blur'}],
            // descOptions: {
            //   content: '月',
            //   style: {
            //     // textAlign: 'center',
            //     // backgroundColor:'#00feff'
            //   }
            // }
          },
          {
            type: 'INPUT_NUMBER',
            label: '法定里程（公里）',
            fieldName: 'mileage',
            placeholder: '请输入',
            initialValue: '',
            rules: [
              {required: true, message: '法定里程不能为空', trigger: 'change'},
              {pattern: /^\d+$/, message: '请输入正整数', trigger: 'blur'}
            ],
            style: {width: '200px'},
            // descOptions: {
            //   content: 'KM',
            //
            // }
          },
          {
            type: 'INPUT_NUMBER',
            label: '法定数量',
            fieldName: 'counts',
            placeholder: '请输入',
            style: {width: '200px'},
            rules: [{required: true, message: '法定数量不能为空', trigger: 'change'}, {pattern: /^\d+$/, message: '请输入正整数', trigger: 'blur'}],
          },
          {
            type: 'TEXT_AREA',
            label: '规则描述',
            fieldName: 'remarks',
            placeholder: '请输入',
            rules: [{required: true, message: '规则描述不能为空', trigger: 'change'}],
            initialValue: '',
            style: {width: '400px'},
          },
          {
            type: 'SELECT',
            label: '状态',
            fieldName: 'isDeleted',
            initialValue: '',
            placeholder: '请选择',
            style: {width: '200px'},
            rules: [{required: true, message: '请选择状态', trigger: 'change'}],
            itemList: [
              { text: '有效', value: 0 },
              { text: '无效', value: 1 }
            ]
          }
        ];
      },
    }
  };
</script>

<!--<style scoped lang="less">-->
<!--  .bg1 {-->
<!--    border: 1px solid @borderColor;-->
<!--    border-radius: @borderRadius;-->
<!--    box-shadow: @boxShadow;-->
<!--    padding: @modulePadding;-->
<!--    padding-left: 0;-->
<!--    padding-top: 15px;-->
<!--    padding-bottom: 15px;-->
<!--  }-->

<!--  .bg2 {-->
<!--    margin-top: 10px;-->
<!--    margin-bottom: 10px;-->
<!--  }-->

<!--  .btn {-->
<!--    text-align: center;-->
<!--  }-->

<!--  .btnStyle {-->
<!--    margin-top: 10px;-->
<!--  }-->
<!--</style>-->
